package gossip;

import lombok.Getter;
import lombok.Setter;

import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;


public class MemberState {
    // Getters
    @Getter
    private final String nodeId;
    @Getter
    private final InetSocketAddress address;
    private final AtomicLong heartbeat = new AtomicLong(1);
    @Getter
    private long updateTime = System.currentTimeMillis();
    @Getter
    @Setter
    private Map<String, String> metadata = new ConcurrentHashMap<>();

    public MemberState(String nodeId, InetSocketAddress address) {
        this.nodeId = nodeId;
        this.address = address;
    }

    public void incrementHeartbeat() {
        heartbeat.incrementAndGet();
        updateTime = System.currentTimeMillis();
    }

    public void updateTimestamp() {
        updateTime = System.currentTimeMillis();
    }

    public long getHeartbeat() { return heartbeat.get(); }

}

